package com.education.welco.pojo;

import com.education.common.utils.UUIDUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;

/**
 * 平台资源表 platform_resources
 *
 * @Author: liftsail
 * @Date: 2022-09-14
 * @Description: 不积跬步无以至千里
 */
@Data
@NoArgsConstructor
public class PlatformResources implements Serializable {
    private static final long serialVersionUID = 1L;


    @ApiModelProperty(value = "主键id")
    private String id;


    @ApiModelProperty(value = "父级id")
    private String pid;


    @ApiModelProperty(value = "文件夹or文件")
    private Boolean isDir;


    @ApiModelProperty(value = "文件|目录名称")
    private String fileName;


    @ApiModelProperty(value = "文件大小")
    private String fileSize;


    @ApiModelProperty(value = "文件路径")
    private String fileUrl;


    @ApiModelProperty(value = "后缀名")
    private String extension;


    @ApiModelProperty(value = "文件备注")
    private String remark;


    @ApiModelProperty(value = "用户id")
    private Long userId;


    @ApiModelProperty(value = "共享状态")
    private Boolean sharedState;


    @ApiModelProperty(value = "删除标志")
    private Boolean isDelete;


    @ApiModelProperty(value = "删除时间")
    private Date deleteTime;


    @ApiModelProperty(value = "创建时间")
    private Date createTime;


    @ApiModelProperty(value = "更新时间")
    private Date updateTime;

    @ApiModelProperty(value = "资源类型 0.文件夹 1.图片 2.视频 3.文件")
    private String resType;
    /**
     * 创建文件夹
     *
     * @param userId   用户ID
     * @param fileName 文件夹名
     * @param pid      父目录ID
     */
    public PlatformResources(Long userId, String fileName, String pid) {
        this.id = UUIDUtils.random32();
        this.userId = userId;
        this.fileName = fileName;
        this.pid = pid;
        this.extension = null;
        this.updateTime = new Date();
        this.createTime = new Date();
        this.isDelete = false;
        this.isDir = true;
        this.deleteTime = null;
    }

    /**
     * 创建文件
     *
     * @param userId    用户ID
     * @param fileName  文件名
     * @param extension 文件扩展名
     * @param pid       父目录ID
     * @param fileSize  文件大小
     * @param fileUrl   文件存储url
     */
    public PlatformResources(Long userId, String fileName, String extension, String pid, String fileSize, String fileUrl) {
        this.id = UUIDUtils.random32();
        this.userId = userId;
        this.fileName = fileName;
        this.extension = extension;
        this.pid = pid;
        this.updateTime = new Date();
        this.createTime = new Date();
        this.isDelete = false;
        this.isDir = false;
        this.deleteTime = null;
        this.fileSize = fileSize;
        this.fileUrl = fileUrl;
    }

}